<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/base.jsp"%>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%int i=1;%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<base href="<%=basePath%>">

<title>参合记录列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery-1.4.4.min.js"></script>
<script src="js/admin.js"></script>
	<script>
		Array.prototype.indexOf = function(val) {
			for (var i = 0; i < this.length; i++) {
				if (this[i] === val) return i;
			}
			return -1;
		};
		Array.prototype.remove = function(val) {
			var index = this.indexOf(val);
			if (index > -1) {
				this.splice(index, 1);
			}
		};
		let sumFree = 0;
		let num = 0;
		const ids = [];
		const free = '${part.partFree}';
		function tickChange(checkBox) {
			const val = checkBox.value;
			if (checkBox.checked === true) {
				ids.push(val);
				sumFree = Number(sumFree) + Number(free);
				num += 1;
			} else {
				ids.remove(val);
				sumFree = Number(sumFree) - Number(free);
				num -= 1;
			}
			$('#partFree').attr('value', sumFree);
		}

		function changeAdd() {
			var famiCode = '${famiCode}';
			var userId = '${sessionScope.userId}';
			window.location.href = '<%=path%>/biz/record/addPart?famiCode=' + famiCode + '&partFree=' + sumFree + '&partNum=' + num + '&creator=' + userId + '&ids=' + ids;
		}
	</script>
</head>
<body>
	<form method="post" action="" id="listform">
		<div class="panel admin-panel">
			<div class="panel-head">
				<strong class="icon-reorder"> 参合登记</strong>
			</div>
			<div class="padding border-bottom">
				<ul class="search" style="padding-left:10px;">
					<li>总计费用：</li>
					<li><input type="text" id="partFree" name="partFree" readonly="readonly"
						class="input"
						style="width:250px; line-height:17px;display:inline-block" /> <a
						href="javascript:void(0)" class="button border-main icon-search"
						onclick="changeAdd()"> 提交</a></li>
				</ul>
			</div>
			<table class="table table-hover text-center">
				<tr>
					<th width="50">序号</th>
					<th width="50" style="text-align:center;">&nbsp;</th>
					<th>农民编号</th>
					<th>农民姓名</th>
					<th>常住地址</th>
					<th>联系电话</th>
				</tr>
				<c:forEach items="${list}" var="i">
				<tr>
					<td><%=i++ %></td>
					<td><input type="checkbox" name="ids"
						value="${i.persCode}" onchange="tickChange(this)"/></td>
					<td>${i.persCode}</td>
					<td>${i.persName}</td>
					<td>${i.liveAddress}</td>
					<td>${i.telephone}</td>
				</tr>
				</c:forEach>
			</table>
			<div class="pagelist">
				<a
					href="<%=path%>/system/RoleServlet?m=list&pageNo=">上一页</a>
				<a href="javascript:void(0)">上一页</a>
				<span class="current"></span>
				<a href="<%=path%>/system/RoleServlet?m=list&pageNo="></a>
				<a
					href="<%=path%>/system/RoleServlet?m=list&pageNo=">下一页</a>
				<a href="javascript:void(0)">下一页</a>
				<a
					href="<%=path%>/system/RoleServlet?m=list&pageNo=">尾页</a>
			</div>
		</div>
	</form>

</body>
</html>
